<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function upperFirst(str) {
                // 拆最外层
            var chararr = str.split(" ")
            // 内层
            for (var i = 0; i < chararr.length; i++) {
                // chararr[i] = chararr[i].charAt(0).toUpperCase() + chararr[i].slice(1)
                
                chararr[i] = chararr[i].split("")[0].toUpperCase() + chararr[i].slice(1);


            }
                console.log(chararr.join(" "));
        }

        upperFirst("i love javascript very much")
    </script>
</head>

<body>

</body>

</html>